package com.zxx.ssm.service;

import com.zxx.ssm.dao.Guoziclass;
import com.zxx.ssm.dao.TeacherStudentClass;
import com.zxx.ssm.dao.TeacherStudentClassExample;
import com.zxx.ssm.dao.TeacherStudentClassLog;
import com.zxx.ssm.exception.AbstractServiceRuntimeException;
import com.zxx.ssm.mapper.GuoziclassMapper;
import com.zxx.ssm.mapper.TeacherStudentClassLogMapper;
import com.zxx.ssm.mapper.TeacherStudentClassMapper;
import com.zxx.ssm.model.biz.StuClasstypeGroupBiz;
import com.zxx.ssm.model.biz.TeaClassCountBiz;
import com.zxx.ssm.model.biz.TeaClasstypeGroupBiz;
import com.zxx.ssm.model.biz.TeaStuClassBiz;
import com.zxx.ssm.service.core.ITeaStuClaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TeacherStudentClassService extends AbstractService<TeacherStudentClass, TeacherStudentClassExample, Integer, TeacherStudentClassMapper> implements ITeaStuClaService{
    @Autowired
    private TeacherStudentClassLogMapper teacherStudentClassLogMapper;

    @Autowired
    private GuoziclassMapper guoziclassMapper;

    public TeacherStudentClassService(TeacherStudentClassMapper teacherStudentClassMapper){
        super(teacherStudentClassMapper);
    }

    public List<TeaStuClassBiz> getAll(Date firstDay, Date lastDay) {
        return this.baseMapper.getAll(firstDay, lastDay);
    }

    public void updateCourse(String[] tscids, Integer guoziClassId) throws AbstractServiceRuntimeException {
        Guoziclass guoziclass = guoziclassMapper.selectByPrimaryKey(guoziClassId);
        for (int i=0;i<tscids.length;i++){
            Integer tscId = Integer.parseInt(tscids[i]);
            TeacherStudentClass teacherStudentClass = this.selectByPrimaryKey(tscId);
            TeacherStudentClassLog teacherStudentClassLog = new TeacherStudentClassLog();
            teacherStudentClassLog.setTeacherid(teacherStudentClass.getTeacherid());
            teacherStudentClassLog.setUserid(teacherStudentClass.getStudentid());
            teacherStudentClassLog.setTimeblockid(guoziclass.getTimeblockid());
            teacherStudentClassLog.setCoursetype(guoziclass.getCoursetype());
            teacherStudentClassLog.setClasstype(guoziclass.getClasstype());
            teacherStudentClassLog.setClassday(guoziclass.getClassday());
            teacherStudentClassLog.setOperator(-1);
            teacherStudentClassLog.setState(0);
            teacherStudentClassLogMapper.insertSelective(teacherStudentClassLog);
            this.delete(tscId);
        }
    }

    public List<TeaClasstypeGroupBiz> getTeaClassCount(Integer teaId) {
        return this.baseMapper.getTeaClassCount(teaId);
    }

    public List<TeaStuClassBiz> getAllTeacherClass(Date firstDay, Date lastDay, Integer teaId) {
        return this.baseMapper.getAllTeacherClass(firstDay, lastDay, teaId);
    }

    public List<StuClasstypeGroupBiz> getStuClassCount(Integer stuId) {
        return this.baseMapper.getStuClassCount(stuId);
    }

    public List<TeaStuClassBiz> getAllStudentClass(Date firstDay, Date lastDay, Integer stuId) {
        return this.baseMapper.getAllStudentClass(firstDay, lastDay, stuId);
    }
}
